import { OrderCreateParams, OrderCreateResult, OrderListParams, OrderListResult, OrderLogisticResult, OrderPreResult, OrderResult } from "@/types/order";
import { httpRequest } from "@/utils/http";

// 获取订单预支付信息
export const getPreOrderAPI = () => {
    return httpRequest<OrderPreResult>({
        method: 'GET',
        url: '/member/order/pre',
    });
};

// 获取立即购买订单预支付信息
export const getBuyNowPreOrderAPI = (data: { skuId: string, count: string, addressId?: string }) => {
    return httpRequest<OrderPreResult>({
        method: 'GET',
        url: '/member/order/pre/now',
        data,
    });
};

// 提交预支付订单
export const postPreOrderAPI = (data: OrderCreateParams) => {
    return httpRequest<OrderCreateResult>({
        method: 'POST',
        url: '/member/order',
        data,
    });
};

// 获取订单信息
export const getOrderByIdAPI = (id: string) => {
    return httpRequest<OrderResult>({
        method: 'GET',
        url: `/member/order/${id}`,
    });
};

// 获取再次购买订单信息
export const getBuyAgainPreOrderByIdAPI = (id: string) => {
    return httpRequest<OrderPreResult>({
        method: 'GET',
        url: `/member/order/repurchase/${id}`,
    });
};

// 获取微信支付参数（上线版）
export const getWeixinPayAPI = (data: { orderId: string }) => {
    return httpRequest<WechatMiniprogram.RequestPaymentOption>({
        method: 'GET',
        url: '/pay/wxPay/miniPay',
        data,
    });
};

// 获取微信支付参数（开发版）
export const getWeixinPayTestAPI = (data: { orderId: string }) => {
    return httpRequest({
        method: 'GET',
        url: '/pay/mock',
        data,
    });
};

// 请求订单发货（开发版）
export const getDeliverByIdTestAPI = (id: string) => {
    return httpRequest({
        method: 'GET',
        url: `/member/order/consignment/${id}`,
    });
};

// 确认收货
export const putOrderReceiveByIdAPI = (id: string) => {
    return httpRequest<OrderResult>({
        method: 'PUT',
        url: `/member/order/${id}/receipt`,
    });
};

// 获取物流信息
export const getLogisticsByIdAPI = (id: string) => {
    return httpRequest<OrderLogisticResult>({
        method: 'GET',
        url: `/member/order/${id}/logistics`,
    });
};

// 删除订单
export const deleteOrderAPI = (data: { ids: string[] }) => {
    return httpRequest({
        method: 'DELETE',
        url: '/member/order',
        data
    });
};

// 取消订单
export const putOrderCancelByIdAPI = (id: string, data: { cancelReason: string }) => {
    return httpRequest<OrderResult>({
        method: 'PUT',
        url: `/member/order/${id}/cancel`,
        data,
    });
};

// 获取订单列表
export const getOrderListAPI = (data: OrderListParams) => {
    return httpRequest<OrderListResult>({
        method: 'GET',
        url: '/member/order',
        data,
    });
};
